// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-Intl-toStringTag
description: >
  Object.prototype.toString utilizes Intl[@@toStringTag] and doesn't special-case Intl namespace object.
info: |
  Object.prototype.toString ( )

  [...]
  14. Else, let builtinTag be "Object".
  15. Let tag be ? Get(O, @@toStringTag).
  16. If Type(tag) is not String, set tag to builtinTag.
  17. Return the string-concatenation of "[object ", tag, and "]".

  Intl [ @@toStringTag ]

  The initial value of the @@toStringTag property is the String value "Intl".
features: [Symbol.toStringTag]
---*/
function Test() {
  assert.sameValue(Intl.toString(), "[object Intl]", "1");
  assert.sameValue(Object.prototype.toString.call(Intl), "[object Intl]", "2");

  Object.defineProperty(Intl, Symbol.toStringTag, { value: "test262", configurable: true });
  assert.sameValue(Intl.toString(), "[object test262]", "3");
  assert.sameValue(Object.prototype.toString.call(Intl), "[object test262]", "4");

  assert(delete Intl[Symbol.toStringTag]);
  assert.sameValue(Intl.toString(), "[object Object]", "5");
  assert.sameValue(Object.prototype.toString.call(Intl), "[object Object]", "6");
  Object.defineProperty(Intl, Symbol.toStringTag, { value: "Intl", configurable: true });
}

// preheat
const NUMBER_OF_PREHEAT = 1;
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
  const globalObject = this;
  globalObject.Test();
}

ArkTools.jitCompileAsync(Test);
assert.sameValue(ArkTools.waitJitCompileFinish(Test), true, '[JIT] JIT disabled.');

// test
const NUMBER_OF_TEST = 1; // or 2
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
  const globalObject = this;
  globalObject.Test();
}